/**
 * @Author: Your name
 * @Date:   2023-02-13 15:27:22
 * @Last Modified by:   Your name
 * @Last Modified time: 2023-02-27 18:54:01
 */
const express = require("express");
const postRouter = express.Router();

postRouter.get("/posts",(req,res,next)=>{
    let slugs = [{slug:"1"},{slug:"2"}]
    res.json(slugs)
    res.end();    

})

postRouter.get("/posts/:id",(req,res,next)=>{
    let postId = req.params["id"];
    console.log("router parameter is "+postId);
    let list = [{
        "id":1,
        "name":"Post Name",
        "time":"2023 07-24"
    },{
        "id":2,
        "name":"Post Name 1",
        "time":"2023 07-25"
    }];
    let timeout = setTimeout(()=>{
        let post = list.filter((item)=>{
            return item.id.toString() === postId.toString();
        })[0];
        res.json(post)
        res.end();    
        clearTimeout(timeout);
    },5000);
})

module.exports = postRouter